// Definition for a binary tree node.
#[derive(Debug, PartialEq, Eq)]
pub struct TreeNode {
  pub val: i32,
  pub left: Option<Rc<RefCell<TreeNode>>>,
  pub right: Option<Rc<RefCell<TreeNode>>>,
}

impl TreeNode {
  #[inline]
  pub fn new(val: i32) -> Self {
    TreeNode {
      val,
      left: None,
      right: None
    }
  }
}
use std::collections::HashSet;
use std::rc::Rc;
use std::cell::RefCell;

struct Solution {}

fn main() {}

impl Solution {
    pub fn num_color(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
        let mut ret: HashSet<i32> = HashSet::new();
        Self::inorder(root, &mut ret);
        ret.len() as i32
    }

    fn inorder(root: Option<Rc<RefCell<TreeNode>>>, set: &mut HashSet<i32>) {
        if root.is_none() {
            return;
        }
        set.insert(root.clone().unwrap().borrow().val);
        Self::inorder(root.clone().unwrap().borrow().left.clone(), set);
        Self::inorder(root.clone().unwrap().borrow().right.clone(), set);
    }
}